<style>
  .error {color : red}
</style>
<div class="container-fluid p-t-10">
  <ol class="breadcrumb" style="font-weight: 700;margin-bottom: 10px">
    <li><a href="#">角色管理</a></li>
    <li class="active">新增角色</li>
  </ol>
  <div class="row">
    <div class="col-lg-12">
      <div class="card">

        <div class="card-body">
          <h1>{$data?'修改':'新增'}角色</h1>
          <form id="add-form" action="{$url}" method="post" class="row">
            <div class="form-group col-md-12 {$data? '':'hide'}">
              <label for="id">角色编号</label>
              <input type="text" class="form-control" id="id" name="id" readonly value="{$data? $data.id:''}"/>
            </div>

            <div class="form-group col-md-12">
              <label for="role_name">角色名称</label>
              <input type="text" class="form-control" id="role_name" name="role_name" value="{$data? $data.role_name:''}" placeholder="请输入角色名称 例如: 角色管理" />
            </div>

            <div class="form-group col-md-12">
              <label >状态</label>
              <div class="clearfix">
                <label class="lyear-radio radio-inline radio-primary">
                  <?php $isChecked = !isset($data) || $data['status'] == 1; ?>

                  <input type="radio" name="status" value="1"  {$isChecked? 'checked' : ''} ><span>启用</span>
                </label>
                <label class="lyear-radio radio-inline radio-primary">
                  <input type="radio" name="status" value="0" {$isChecked? '' : 'checked'}><span>禁用</span>
                </label>
              </div>
            </div>
            <div class="form-group col-md-12">
              <button type="submit" class="btn btn-primary ajax-post" target-form="add-form">确 定</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
<script>

  $(function(){
    $("#add-form").validate({
      rules: {
          role_name: {
          required: true,
          remote:{
            url: '/role/checkName',
            type: "post",               //数据发送方式
            dataType: "json",           //接受数据格式
            data: {                     //要传递的数据
                'role_name': function() {
                return $("#role_name").val();
              },
              id:function() {
                var $id = $("#id");
                if($id.length > 0){
                  return $id.val();
                }
                return 0;
              },
            }
          }
        }
      },
      messages: {
          role_name:{
          remote:'角色名重复'
        }
      },
    });
  });
</script>


